﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ibba.src.slcomponentes
{
    public partial class WaitLoading : UserControl
    {

        // Using a DependencyProperty as the backing store for IsWait.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsWaitProperty = DependencyProperty.Register("IsWait", typeof(bool), typeof(WaitLoading), new PropertyMetadata(default(bool)));

        public bool IsWait
        {
            get { return (bool)GetValue(IsWaitProperty); }
            set { 
                SetValue(IsWaitProperty, value);
                if (value == true)
                    this.Start();
                else
                    this.Stop();
            }
        }

        public WaitLoading()
        {
            InitializeComponent();

            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                canvasLoading.Visibility = Visibility.Collapsed;
        }

        private void Start()
        {
            canvasLoading.Visibility = Visibility.Visible;
            IndicatorStoryboard.Begin();
        }

        private void Stop()
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                canvasLoading.Visibility = Visibility.Collapsed;

            IndicatorStoryboard.Stop();
        }
    }
}
